#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

#define localize1(bundle, str) [bundle localizedStringForKey:str value:str table:nil]
#define localize(bundle, str) FWLocalise(bundle, str)

#ifdef DEBUG
#define DebugLog(s, ...) XLog(s, ##__VA_ARGS__)
#else
#define DebugLog(s, ...)
#endif

#define XLog(s, ...) NSLog(s, ##__VA_ARGS__)


enum FWDateFormatterFormat {
    FWDateFormatterLongFormat = 0,
    FWDateFormatterLongAbbreviatedFormat = 1,
    FWDateFormatterNormalFormat = 2,
    FWDateFormatterCompressedFormat = 3,
    FWDateFormatterTimeOnlyFormat = 4
};

enum FWWeekdayName {
    FWWeekdayNameUnknown = 0,
    FWWeekdayNameMonday = 1,
    FWWeekdayNameTuesday = 2,
    FWWeekdayNameWednesday = 3,
    FWWeekdayNameThursday = 4,
    FWWeekdayNameFriday = 5,
    FWWeekdayNameSaturday = 6,
    FWWeekdayNameSunday = 7
};

extern NSNumber* const NSNumberYES;
extern NSNumber* const NSNumberNO;
extern NSNumber* const NSNumber0;
extern NSNumber* const NSNumber1;

extern NSInteger const SECONDS_IN_HOUR;
extern NSInteger const SECONDS_IN_MINUTE;

extern CGSize FWGetCurrentScreenSize();
extern BOOL FWIsDeviceAnIPad();
NSString* FWBase64EncodeString(NSString* src);
NSString* FWXMLEncodeString(NSString *src);
BOOL FWIsColorDark(UIColor *color);

NSString* FWObjectDescription(NSObject* obj);
NSString* FWStringValueFromData(NSData* data);

UIView* FWSuperViewOfClass(UIView* view, Class claz);

NSNumber* FWNewNumberWithInt(int i);

NSDate* FWUTCForLocalDate(NSDate* date);

NSDate* FWLocalDateForUTC(NSDate* date);
NSDate* FWLocalDateForLocalMidnightOnDate(NSDate* date);
NSDate* FWLocalDateForLocalMidnight();
NSInteger FWSecondsWithinLocalDate(NSDate* date);

BOOL FWIsLocalDateSameWeek(NSDate* date1, NSDate* date2);
BOOL FWIsLocalDateSameDay(NSDate* date1, NSDate* date2);
BOOL FWIsLocalDateThisWeek(NSDate* date);
BOOL FWIsLocalDateToday(NSDate* date);
BOOL FWIsLocalDateTomorrow(NSDate* date);
BOOL FWIsLocalDateYesterday(NSDate* date);
FWWeekdayName FWLocalWeekdayName(NSDate* date);

NSString* FWLocalise(NSBundle* bundle, NSString* str);

NSString* FWLocalDateStringForUTCDate(NSDate* date, FWDateFormatterFormat format, BOOL time, NSBundle* bundle);

#ifdef DEBUG
NSString* FWDebugTimeStringForUTCDate(NSDate* date);
#endif

#ifdef DEVELOPMENT_MODE
void FWTestDateFunctions();
#endif


@interface NSString (FWCommon)

- (NSString*)stringValue;

@end


@interface NSMutableString (FWCommon)
    
- (void)appendString:(NSString*)str withSeparator:(NSString*)sep;

@end


@interface NSDate (FWCommon)

- (BOOL)isNull;
+ (NSDate*)nullDate;
+ (NSDate*)nullableDateWithTimeIntervalSinceReferenceDate:(NSTimeInterval)interval;

- (BOOL)isEarlierThanDate:(NSDate*)other;
- (BOOL)isLaterThanDate:(NSDate*)other;
- (BOOL)isEqualOrEarlierThanDate:(NSDate*)other;
- (BOOL)isEqualOrLaterThanDate:(NSDate*)other;

#ifdef DEVELOPMENT_MODE
+ (NSDate*)dateTodayAtHour:(NSInteger)hour minute:(NSInteger)minute section:(NSInteger)second;
#endif

@end

extern void XYLog(NSString *format, ...);
extern void XYTimeLog(CFAbsoluteTime *time, NSString *format, ...);
